//
//  SuccessViewController.m
//  DaDaBao
//
//  Created by admin on 15/8/27.
//  Copyright (c) 2015年 User. All rights reserved.
//

#import "SuccessViewController.h"

@interface SuccessViewController ()
@property (nonatomic,copy)NSString * titleString;
@property (nonatomic,copy)NSString * tips;
@end

@implementation SuccessViewController
-(id)initWithTitle:(NSString *)title andTips:(NSString *)tips
{
    if (self = [super init])
    {
        _titleString = title;
        _tips = tips;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor hexStringToColor:@"#ebebeb"];
    
    [self createUI];
}
-(void)createUI
{
    TopView *topView =[[TopView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 64.0f)];
    [topView setTitile:_titleString];
    
    [self.view addSubview:topView];
    
    
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-38, 64.0f+100.0f, 77.0f, 77.0f)];
    imgView.image = [UIImage imageNamed:@"sucess"];
    [self.view addSubview:imgView];
    
    UILabel *textLab = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, imgView.frame.origin.y+imgView.frame.size.height+20.0f, SCREEN_WIDTH, 25.0f)];
    textLab.text = _tips;
    textLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:textLab];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(15.0f, textLab.frame.size.height+textLab.frame.origin.y+30.0f, SCREEN_WIDTH-30.0f, 35.0f*HSCALE)];
    backBtn.backgroundColor = [UIColor hexStringToColor:RED_COLOR_VALUE];
    backBtn.layer.cornerRadius = 5.0f;
    [backBtn setTitle:@"返回" forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(buttonBackTapped:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];

}
-(void)buttonBackTapped:(id)sender
{
    NSArray *listArray = self.navigationController.viewControllers;
    id tabBar = [listArray objectAtIndex:2];
    
    if([[tabBar class] isSubclassOfClass:[UITabBarController class]])
    {
        UITabBarController *tabBarCon = tabBar;
        tabBarCon.selectedIndex = 2;
        [self.navigationController popToViewController:[listArray objectAtIndex:2] animated:TRUE];
    }
    else
    {
        UITabBarController *tabBarCon = [listArray objectAtIndex:1];
        tabBarCon.selectedIndex = 2;
        [self.navigationController popToViewController:[listArray objectAtIndex:1] animated:TRUE];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
